home *** CD-ROM | disk | FTP | other *** search
- MKF2C(1) Last changed: 12-23-98
-
-
- NNAAMMEE
- mmkkff22cc - Generate FORTRAN-C interface routines
-
- SSYYNNOOPPSSIISS
- mmkkff22cc [ _o_p_t_i_o_n_s ] [ ccpprroogg..ffcc [ ccpprroogg..ss ] ]
-
- IIMMPPLLEEMMEENNTTAATTIIOONN
- IRIX systems
-
- DDEESSCCRRIIPPTTIIOONN
- mmkkff22cc is used to generate assembly-language routines to provide
- greater flexibility when calling a C function from a FORTRAN routine.
-
- mmkkff22cc accepts as input a set of C functions, and produces an
- assembly-language interface routine in the output file. If the input
- and output files are not specified, mmkkff22cc reads from stdin and writes
- to stdout. The input may be a copy of the actual C file being
- interfaced, perhaps filtered by the program eexxttcceennttrryy(1). The output
- of mmkkff22cc is an assembly-language (..ss) file that must be assembled with
- aass(1), and loaded with the FORTRAN and C routines that are to be
- interfaced.
-
- The assembly-language output is KPIC code which must be assembled with
- the --KKPPIICC option to aass(1) unless an unshared .o is desired.
-
- mmkkff22cc uses the parameter declarations in the C function headers to
- transform each parameter of the calling language to that of the
- receiving language. The standard basic C types attached to the
- parameters are used to determine the object each parameter represents
- - i.e., whether it is a value or pointer, its size, whether it is
- unsigned, etc.
-
- For C functions in K&R style, the opening and closing brace of the
- function body must be present. Information in the body of the
- function is ignored. For C functions in ANSI C function prototype
- style, the function may be either a definition (and whatever is
- between the opening and closing brace is ignored) or a declaration
- (ie, with ; rather than {}). Function parameters in ANSI C style
- function prototypes need not name the parameters. Function parameters
- in ANSI C style function prototypes cannot use typedef names to
- declare parameter types.
-
- mmkkff22cc expects its input to consist solely of the functions it is to
- interface, comments, and lines which begin with the preprocessor
- control character '#'. It can match braces, enabling it to bound
- function bodies. It cannot, however, understand other C constructs
- normally occurring at the global level (typedefs, structure
- declarations, data declarations, function prototypes, etc.). Such
- unrecognized constructs must be eliminated from the input (this is the
- purpose of eexxttcceennttrryy(1)).
-
- mmkkff22cc will ignore functions of storage class ssttaattiicc.
-
- The simplest way to generate an interface for a C function is to
- hand-code a copy of the function which consists of the entry and
- parameter declarations with an empty body. This stub, which is
- traditionally suffixed with ..ffcc is then used as input to mmkkff22cc, and
- the resultant ..ss file is assembled and linked into the executable.
- The root name of the stub file must differ from the root name of the
- file containing the actual C functions (so that the name of the
- resultant ..oos differ). NOTE: The -KPIC switch must be given to aass(1)
- unless the object is to be non-shared.
-
- mkf2c foo.fc foo.s
- as -KPIC foo.s -o foo.o
-
- It is also possible to create wrappers from existing C source code.
- This is done by adding special rules to your makefile and adding
- special comments around each function for which an interface is to be
- generated. See the example at the end of this man page.
-
- The following are options to mmkkff22cc(1):
-
- --3322 Generate wrappers with (old) 32-bit calling conventions. At
- this time, it is the default, but may change as different
- ABIs become the future default.
-
- --6644 Generate wrappers with 64-bit pointer sizes, and using the
- 64 bit calling conventions.
-
- --nn3322 Generate wrappers with the n32 calling conventions.
-
- --ff Suppress extending floats to doubles across the call.
- Normally, formal parameters of type ffllooaatt in the (K&R) C
- input to mmkkff22cc are dereferenced and converted to type ddoouubbllee
- across the interface, to conform to C calling conventions.
- This option suppresses the conversion to ddoouubbllee. If this
- option is selected, the receiving routine in C should have a
- pprroottoottyyppee with the ffllooaatt parameters declared correctly. For
- declarations input to mmkkff22cc in ANSI C style function
- prototypes float arguments are not extended, so --ff need not
- be supplied.
-
- --oooouuttppuutt Name the output file oouuttppuutt. If the output filename is not
- specified by a --oo ffiilleennaammee switch, mmkkff22cc will use the second
- filename appearing in its argument list as the output file
- name. This method must be used to generate an interface
- routine in a file when the input is from ssttddiinn.
-
- --UU Normally, upper case characters appearing in FORTRAN
- external names are mapped to lower case. This option
- suppresses that mapping, allowing FORTRAN external names to
- be of mixed case. This option should be used in conjunction
- with the --UU option to ff7777(1).
-
- --ssiiggnneedd,,--uunnssiiggnneedd
- Specify the ssiiggnneedd attribute of single-character parameters.
- The setting of this option determines whether a scalar
- parameter of type cchhaarr (in the C input to mmkkff22cc), which
- corresponds to a FORTRAN argument of type cchhaarraacctteerr**11,
- should be sign-extended across the interface. The default
- setting is uunnssiiggnneedd.
-
- --uu Keep underscores in function names. By default underscores
- are removed and a warning is issued.
-
- --ll By default, mmkkff22cc truncates FORTRAN external names to ssiixx
- characters to conform to the ANSI standard and to be
- backwards-compatible with the IRIS 4D Series. This switch
- allows the maximum number of characters in FORTRAN external
- names to be the same as that enforced by the FORTRAN front-
- end (currently 32). If this switch is not specified, the
- FORTRAN program should have the C function name truncated to
- six characters at the call.
-
- --ww Inhibit the generation of warning messages. Because
- creating wrappers can cause confusion, mmkkff22cc issues warning
- messages for constructs that will result in an interface
- that is not normal for C (i.e., the C side of the interface
- must take special precautions when accessing the parameters
- or naming the routines). An example of this would be
- passing a FORTRAN character variable as a C character array.
- mmkkff22cc knows that this situation requires C to use special
- care when manipulating the string, as it is not null-
- terminated, and, hence, it generates a warning message. It
- is recommended that --ww only be used by programmers
- experienced with the generation of wrappers.
-
- --ccaallll__ssaammee__ddssoo
- This is used when the wrapper and the target C function will
- be placed in the same DSO. A further optimization is taken
- which removes the restoring of the gp register after the
- call return.
-
- EEXXAAMMPPLLEESS
- In the following example, a FORTRAN program wants to call a C function
- AAllllPPaarraammeetteerrss with many parameters. The FORTRAN program is in the
- file ff..ff and the C function is in the file cc..cc. These are the only
- two files in the program. The special comments /*CENTRY*/ and
- /*ENDCENTRY*/ have been added to the C source code to bracket the
- function for which an interface is to be generated. The following is
- the C function header:
-
- /* CENTRY */
- AllParameters(i,s,c,cptr,ptr1,ptr2,ar1,f,d,d1,struct1,string1,string2,u)
- short s;
- char c,*cptr;
- int *ptr1;
- char *ptr2[];
- short ar1[];
- float f;
- double d,*d1;
- struct test_s *struct1;
- char string1[],string2[30];
- sometype u;
- {
- /*
- The C function body is ignored by mkf2c.
- */
- }
- /* ENDCENTRY */
-
- When this function is run through mmkkff22cc, a complaint will be issued
- about not understanding the type of parameter uu. It will be assumed
- to be a simple pointer. Additionally, a warning about passing the
- parameters, ssttrriinngg11 and ssttrriinngg22, as simple pointers will be issued.
- (These FORTRAN character variables each have an associated length that
- is passed as a hhiiddddeenn parameter to the C function, at the end of the
- parameter list. These additional parameters may be accessed by the C
- function by the use of the vvaarraarrggss macros. See the FFOORRTTRRAANN LLaanngguuaaggee
- RReeffeerreennccee MMaannuuaall for more information.)
-
- The ii parameter will be assumed to be of type iinntt, as it is by the C
- compiler ccccoomm during compilation.
-
- Several items are noteworthy about the parameters in this example.
- The parameters ii, ss, cc, ff, and dd will be dereferenced across the call.
- The parameter ff will be extended to a ddoouubbllee across the call unless
- the --ff switch is given to mmkkff22cc(1). The parameters ppttrr11, ppttrr22, aarr11,
- dd11, ssttrruucctt11, ssttrriinngg11, and ssttrriinngg22 will be passed as simple pointers.
- The FORTRAN cchhaarraacctteerr**11 variable which is passed as cc will be
- dereferenced and extended to a lloonngg across the call. If the --ssiiggnneedd
- switch is specified, cc will be sign-extended when being dereferenced.
- A copy of parameter ccppttrr will be made and the copy null-terminated. A
- pointer to this copy will be passed. The C entry point will be named
- AAllllPPaarraammeetteerrss. The FORTRAN entry point name depends on whether or not
- the --UU and/or the --ll switches have been given. The various
- combinations of these switches and their effect is detailed below:
-
- Switches
- FORTRAN Entry
-
- <<nnoonnee>>
- aallllppaarr__
-
- --ll aallllppaarraammeetteerrss__
-
- --UU AAllllPPaarr__
-
- --ll --UU
- AAllllPPaarraammeetteerrss__
-
- The program can be made easily and the interface generated
- automatically by adding the following special rules to your makefile:
-
- # .fc must be added to your SUFFIXES between .c and .o
- .SUFFIXES:
- .SUFFIXES: .o .fc .c .s .f
-
- F2CFLAGS=
- ASFLAGS=-KPIC
-
- test: f.o c.o
- f77 -o test f.o c.o
-
- # note -- each .c file containing routines to be interfaced must have
- # a dependency such as the following
- c.o: c.fc
-
- .fc.o:
- cc $(CFLAGS) -c $*.c
- mkf2c $(F2CFLAGS) $< $*.s
- as $(ASFLAGS) -o $*.wo $*.s
- ld -r $*.o $*.wo -o $*.tmp
- mv $*.tmp $*.o
- rm -f $*.s $*.wo
-
- .c.fc:
- extcentry $*.c $*.fc
-
-
- clean:
- rm -f *.o test *.fc
-
- In the make, the program eexxttcceennttrryy will be run on cc..cc to produce cc..ffcc.
- This program (see eexxttcceennttrryy(1)) will copy to cc..ffcc all text in cc..cc
- which is between the special comments ** CCEENNTTRRYY ** and ** EENNDDCCEENNTTRRYY **.
- mmkkff22cc will then be run on cc..ffcc, and the make variable FF22CCFFLLAAGGSS will be
- passed to it. The C source will be compiled with cccc(1) (using cccc
- $$CCFFLLAAGGSS), and the output of mmkkff22cc will be assembled (with aass
- $$AASSFFLLAAGGSS). These two ..oos will then be loaded together into a single
- relocatable named cc..oo.
-
- If it is desired to pass mmkkff22cc(1) some flags (e.g., --ll and --ssiiggnneedd),
- the mmaakkee variable FF22CCFFLLAAGGSS should be set in the makefile, as
-
- F2CFLAGS = -signed -l
-
- DDIIAAGGNNOOSSTTIICCSS
- mmkkff22cc can detect such things as a formal parameter having its type
- declared when it is not in the formal parameter list. A few such
- cases give intelligible error messages. The program will issue
- warnings about types it does not understand. The default type
- assigned in such cases is ssiimmppllee ppooiinntteerr. mmkkff22cc will also delete
- characters from FORTRAN entry names that are illegal (such as
- underscores) and issue a warning message. Most errors that the
- programs detect are indicated only by the source line number.
-
- If mmkkff22cc encounters an error that it cannot remedy, it will abort,
- giving the line number on which the error occurred. The resultant ..ss
- file will be removed, and an error exit will be taken.
-
- Because of its limited error diagnostic ability, it is advisable to
- use cccc(1) to determine whether the input syntax is correct before
- passing it to mmkkff22cc..
-
- BBUUGGSS
- mmkkff22cc does not understand the ANSI notation aa((vvooiidd)) as meaning a
- function with no arguments.
-
- In ANSI C style function prototypes, ttyyppeeddeeff names cannot be used.
-
- SSEEEE AALLSSOO
- eexxttcceennttrryy(1), cccc(1), FORTRAN Language Reference Manual
-
- This man page is available only online.
-
-